package com.zw.yzk.kabu.mapper;

import com.zw.yzk.kabu.data.network.entity.AlbumEntity;
import com.zw.yzk.kabu.model.AlbumModel;
import com.zw.yzk.kabu.utils.TimeFormatUtils;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * Created by zhanwei on 2017/7/5.
 */

public class AlbumMapper {

    @Inject
    public AlbumMapper() {
    }

    public List<AlbumModel> transfer(AlbumEntity entity) {
        List<AlbumModel> mList = new ArrayList<>();
        for(AlbumEntity.Item item : entity.result.albumList) {
            AlbumModel model = new AlbumModel();
            model.setCosId(item.cosId);
            model.setImageId(item.id);
            model.setImageUrl(item.img);
            try {
                model.setDate(TimeFormatUtils.stringDateFormat(item.time, "yyyy-MM-dd HH:mm:ss", "yyyy-MM"));
                String[] d = model.getDate().split("-");
                model.setType(Integer.parseInt(d[0]) * 100 + Integer.parseInt(d[1]));
            } catch (Exception e) {
                model.setDate(item.time);
                model.setType(0);
            }
            mList.add(model);
        }
        return mList;
    }
}
